# coding=utf-8

from app.model import Users, Room
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, TextAreaField, SubmitField
from wtforms.validators import Required, Email, EqualTo
from wtforms import ValidationError

class Userform(FlaskForm):
    name = StringField('What is your name? QAQ', validators=[Required()])
    password = PasswordField('Password ?', validators=[Required()])
    submit = SubmitField('Submit!')

class Registerform(FlaskForm):
    name = StringField('What is your name? QwQ', validators=[Required()])
    password = PasswordField('Password', validators=[Required(), EqualTo('password2', message='Passwords must match.')])
    password2 = PasswordField('Password again', validators=[Required()])
    submit = SubmitField('Submit!')

    def validate_name(self, field):
        if Users.objects(name=field.data).first():
            return ValidationError('Name already registered!')

class Create_Room_form(FlaskForm):
    name = StringField('The Room\'s name', validators=[Required()])
    Introduction = TextAreaField('Introduction')

    def validate_name(self, field):
        if Room.objects(name=field.data).first():
            return ValidationError('Name already registered!')

class Create_Notice_form(FlaskForm):
    Date = StringField('Date', validators=[Required()])
    Introduction = TextAreaField('Introduction')
